package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;

import javax.servlet.http.HttpSession;

/**
 * @author lixu
 *
 * @SessionAttributes(value = {"name"}):
 *    1、当同学们往request域中保存数据的时候 同时在Session中也保存一份
 *    {"name"}: request域保存数据：数据的Key值必须是name
 *
 */
@Controller
@SessionAttributes(value = {"name","gender"})//影响到了整体类
public class SesssionController {


    @RequestMapping("/session/add")
    public String add(Model model){
        //保存大狗到request域中 Session域中有吗？
        model.addAttribute("name","大狗");
        model.addAttribute("gender","毛狗");
        model.addAttribute("dog","真狗");
        return "add";
    }
    @RequestMapping("/session/update")
    public String update(Model model){
        //保存大狗到request域中 Session域中有吗？
        model.addAttribute("name","update大狗");
        model.addAttribute("gender","update毛狗");
        return "add";
    }
    /**
     * Session 在同学们不清理的情况下：一直存活 直到过期
     *   默认：情况下：30分钟
     */
    @RequestMapping("/session/clean")
    public String clean(SessionStatus status,Model model){
        //保存大狗到request域中 Session域中有吗？
        model.addAttribute("name","大狗");
        model.addAttribute("gender","毛狗");
        model.addAttribute("dog","真狗");

        //将上面@SessionAttributes(value = {"name","gender"}) 所生产的数据清理掉
        status.setComplete();
        //转发
        return "forward:/session/list";
    }
    @RequestMapping("/session/list")
    public String list(){

        return "add";
    }
}
